package gedis

import "github.com/gomodule/redigo/redis"

type RedisBit struct {
	*RedisCache
}

func (c *RedisBit) SetBit(key string, offset, value int64) *Reply {
	return getReply(c.Do("setbit", key, offset, value))
}

func (c *RedisBit) GetBit(key string, offset int64) *Reply {

	return getReply(c.Do("getbit", key, offset))
}

func (c *RedisBit) BitCount(key string, interval ...int64) *Reply {

	if len(interval) == 2 {
		return getReply(c.Do("bitcount", key, interval[0], interval[1]))
	}
	return getReply(c.Do("bitcount", key))
}

// opt 包含 and、or、xor、not
func (c *RedisBit) BitTop(opt, destKey string, keys ...string) *Reply {

	return getReply(c.Do("bitop", opt, redis.Args{}.Add(keys).AddFlat(keys)))
}
